#include <rtthread.h>
#include <board.h>

#include <base/g2d.h>
#include <base/timer.h>
#include <base/lcd.h>
#include <base/idle.h>
#include <lcd/lcd_mem_bgr565.h>
#include <lcd/lcd_mem_bgra8888.h>
#include <tkc/mem.h>
#include <tkc/platform.h>
#include <main_loop/main_loop_simple.h>

#include "../lcd.h"

#define SDRAM_MEMORY		0XC0000000

#define PIXSIZE 			2
#define PER_FB_SIZE			(lcddev.width * lcddev.height * PIXSIZE)

#define FB_START			(SDRAM_MEMORY)
#define FB1 				(FB_START)
#define FB2 				(FB_START + PER_FB_SIZE)
#define FB_END				(FB2 + PER_FB_SIZE)


#define AWTK_MEMBER_SIZE	(8*1024*1024)
#define AWTK_MEMBER			(FB_END + AWTK_MEMBER_SIZE)


extern int gui_app_start(int lcd_w, int lcd_h);

uint64_t get_time_ms64()
{
	return HAL_GetTick();
}

void sleep_ms(uint32_t ms)
{
	rt_thread_mdelay(ms);
}

ret_t platform_prepare(void)
{
	return tk_mem_init((void *)AWTK_MEMBER, AWTK_MEMBER_SIZE);
}

uint8_t platform_disaptch_input(main_loop_t *loop)
{
	return 0;
}

lcd_t *platform_create_lcd(wh_t w, wh_t h)
{
	return lcd_mem_bgr565_create_double_fb(w, h, FB1, FB2);
}

#include "main_loop/main_loop_raw.inc"



#include "tkc/mem.h"
#include "lcd/lcd_reg.h"

typedef uint16_t pixel_t;

#define LCD_FORMAT BITMAP_FMT_BGR565
#define pixel_from_rgb(r, g, b)                                                \
  ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))
#define pixel_to_rgba(p)                                                       \
  { (0xff & ((p >> 11) << 3)), (0xff & ((p >> 5) << 2)), (0xff & (p << 3)) }

#define set_window_func LCD_Set_Window
#define write_data_func LCD_WriteData_Color

#include "base/pixel.h"
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem_fragment.inc"
